{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-03-18T14:09:17.039970Z",
     "start_time": "2025-03-18T14:09:16.001178Z"
    }
   },
   "source": [
    "from time import sleep\n",
    "\n",
    "# Wrap tqdm() around any iterable:\n",
    "from tqdm import tqdm\n",
    "\n",
    "text = \"\"\n",
    "for char in tqdm([\"a\", \"b\", \"c\", \"d\"]):\n",
    "    sleep(0.25)\n",
    "    text = text + char"
   ],
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 4/4 [00:01<00:00,  3.90it/s]\n"
     ]
    }
   ],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-18T14:09:18.251757Z",
     "start_time": "2025-03-18T14:09:17.049523Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# trange(i) is a special optimised instance of tqdm(range(i)):\n",
    "from tqdm import trange\n",
    "\n",
    "for i in trange(100):\n",
    "    sleep(0.01)"
   ],
   "id": "7b6fbcdefee51ebb",
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 100/100 [00:01<00:00, 83.61it/s]\n"
     ]
    }
   ],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-18T14:09:19.362304Z",
     "start_time": "2025-03-18T14:09:18.330514Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# Instantiation outside of the loop allows for manual control over tqdm():\n",
    "pbar = tqdm([\"a\", \"b\", \"c\", \"d\"])\n",
    "for char in pbar:\n",
    "    sleep(0.25)\n",
    "    pbar.set_description(\"Processing %s\" % char)"
   ],
   "id": "ce55b479dafc41cb",
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Processing d: 100%|██████████| 4/4 [00:01<00:00,  3.89it/s]\n"
     ]
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-18T14:09:20.425109Z",
     "start_time": "2025-03-18T14:09:19.370984Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# Manual control of tqdm() updates using a with statement:\n",
    "with tqdm(total=100) as pbar:\n",
    "    for i in range(10):\n",
    "        sleep(0.1)\n",
    "        pbar.update(10)"
   ],
   "id": "31a45d1ddf6ed11a",
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 100/100 [00:01<00:00, 95.24it/s]\n"
     ]
    }
   ],
   "execution_count": 4
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-18T14:09:21.497217Z",
     "start_time": "2025-03-18T14:09:20.434264Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# with is also optional (you can just assign tqdm() to a variable, but in this case don’t forget to del or close() at the end:\n",
    "\n",
    "pbar = tqdm(total=100)\n",
    "for i in range(10):\n",
    "    sleep(0.1)\n",
    "    pbar.update(10)\n",
    "pbar.close()"
   ],
   "id": "164c4fc3ad507d9d",
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 100/100 [00:01<00:00, 94.49it/s]\n"
     ]
    }
   ],
   "execution_count": 5
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-18T14:09:31.637895Z",
     "start_time": "2025-03-18T14:09:21.505976Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# Custom information can be displayed and updated dynamically on tqdm bars with the desc and postfix arguments:\n",
    "\n",
    "from tqdm import tqdm, trange\n",
    "from random import random, randint\n",
    "from time import sleep\n",
    "\n",
    "with trange(10) as t:\n",
    "    for i in t:\n",
    "        # Description will be displayed on the left\n",
    "        t.set_description('GEN %i' % i)\n",
    "        # Postfix will be displayed on the right,\n",
    "        # formatted automatically based on argument's datatype\n",
    "        t.set_postfix(loss=random(), gen=randint(1, 999), str='h',\n",
    "                      lst=[1, 2])\n",
    "        sleep(0.5)\n",
    "\n",
    "with tqdm(total=10, bar_format=\"{postfix[0]} {postfix[1][value]:>8.2g}\",\n",
    "          postfix=[\"Batch\", {\"value\": 0}]) as t:\n",
    "    for i in range(10):\n",
    "        sleep(0.5)\n",
    "        t.postfix[1][\"value\"] = i / 2\n",
    "        t.update()"
   ],
   "id": "ecf065f73c961981",
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "GEN 9: 100%|██████████| 10/10 [00:05<00:00,  1.98it/s, gen=323, loss=0.921, lst=[1, 2], str=h]\n",
      "Batch      4.5\n"
     ]
    }
   ],
   "execution_count": 6
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-18T14:09:31.652926Z",
     "start_time": "2025-03-18T14:09:31.647631Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# Additional bar_format parameters may also be defined by overriding format_dict, and the bar itself may be modified using ascii:\n",
    "from tqdm import tqdm\n",
    "\n",
    "\n",
    "class TqdmExtraFormat(tqdm):\n",
    "    \"\"\"Provides a `total_time` format parameter\"\"\"\n",
    "\n",
    "    @property\n",
    "    def format_dict(self):\n",
    "        d = super().format_dict\n",
    "        total_time = d[\"elapsed\"] * (d[\"total\"] or 0) / max(d[\"n\"], 1)\n",
    "        d.update(total_time=self.format_interval(total_time) + \" in total\")\n",
    "        return d\n",
    "\n",
    "\n",
    "for i in TqdmExtraFormat(\n",
    "        range(9), ascii=\" .oO0\",\n",
    "        bar_format=\"{total_time}: {percentage:.0f}%|{bar}{r_bar}\"):\n",
    "    if i == 4:\n",
    "        break"
   ],
   "id": "54d7c994981552aa",
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "00:00 in total: 44%|0000.     | 4/9 [00:00<00:00, 13888.42it/s]\n"
     ]
    }
   ],
   "execution_count": 7
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-18T14:09:44.096554Z",
     "start_time": "2025-03-18T14:09:31.668925Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# tqdm supports nested progress bars. Here’s an example:\n",
    "from tqdm.auto import trange\n",
    "from time import sleep\n",
    "\n",
    "for i in trange(4, desc='1st loop'):\n",
    "    for j in trange(5, desc='2nd loop'):\n",
    "        for k in trange(50, desc='3rd loop', leave=False):\n",
    "            sleep(0.01)"
   ],
   "id": "5877ef1e43bb4896",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1st loop:   0%|          | 0/4 [00:00<?, ?it/s]"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "9429b02b1a504be0bba532b432c4c59c"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "2nd loop:   0%|          | 0/5 [00:00<?, ?it/s]"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "d0b0758241fb4bf3af7ceb031b765fc0"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "3rd loop:   0%|          | 0/50 [00:00<?, ?it/s]"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "c0cbd430fa9943abbcbb3816eea26f0a"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "3rd loop:   0%|          | 0/50 [00:00<?, ?it/s]"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "9517be5161734d22a97810f5c400320b"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "3rd loop:   0%|          | 0/50 [00:00<?, ?it/s]"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "0778f4fd5e4441d39346364fecae112e"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "3rd loop:   0%|          | 0/50 [00:00<?, ?it/s]"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "cc3f82d265a24f26aea009d0572490ab"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "3rd loop:   0%|          | 0/50 [00:00<?, ?it/s]"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "b81c1867f34e45b5a3f031eae40fba2e"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "2nd loop:   0%|          | 0/5 [00:00<?, ?it/s]"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "9a2170e6ad11410b98508d6effb08e60"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "3rd loop:   0%|          | 0/50 [00:00<?, ?it/s]"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "f7d60540c4cb4b89bdc8dee35af57eab"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "3rd loop:   0%|          | 0/50 [00:00<?, ?it/s]"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "8e8c941e9f0f42819a3d3d77df881538"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "3rd loop:   0%|          | 0/50 [00:00<?, ?it/s]"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "6f82d8df661a432ab29f07e17109a147"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "3rd loop:   0%|          | 0/50 [00:00<?, ?it/s]"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "bbadc73074bb4a62991451e8241e6f7e"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "3rd loop:   0%|          | 0/50 [00:00<?, ?it/s]"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "b0df23e97b7c49cc8b32a5d003ffe295"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "2nd loop:   0%|          | 0/5 [00:00<?, ?it/s]"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "86432438197744f5a65de41db1ecc396"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "3rd loop:   0%|          | 0/50 [00:00<?, ?it/s]"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "d1c9840b92c9478eab072a7571f16b00"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "3rd loop:   0%|          | 0/50 [00:00<?, ?it/s]"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "6aec76b9a6cf4e35b81c30776c5715e8"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "3rd loop:   0%|          | 0/50 [00:00<?, ?it/s]"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "5c2eb3a2bdc14cb6b6809cbab8d9443d"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "3rd loop:   0%|          | 0/50 [00:00<?, ?it/s]"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "fa108d4d980e4769868b3651cea3657f"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "3rd loop:   0%|          | 0/50 [00:00<?, ?it/s]"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "2b73a7ac2c6547fe9278f1bc0dc8b09a"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "2nd loop:   0%|          | 0/5 [00:00<?, ?it/s]"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "e04193bd411b4c2599c7e71b34ea3618"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "3rd loop:   0%|          | 0/50 [00:00<?, ?it/s]"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "89ca8025daa74b7aa7845e8d69c626dd"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "3rd loop:   0%|          | 0/50 [00:00<?, ?it/s]"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "e3c36e5d8ed64162aa55471b4a206b80"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "3rd loop:   0%|          | 0/50 [00:00<?, ?it/s]"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "028e04d71ce840d6bc423abd308c30ec"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "3rd loop:   0%|          | 0/50 [00:00<?, ?it/s]"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "8656678b39a4498bb985f535a3dd8e28"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "3rd loop:   0%|          | 0/50 [00:00<?, ?it/s]"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "21608c34f2964940969599e229f52f09"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "execution_count": 8
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-18T14:10:12.908759Z",
     "start_time": "2025-03-18T14:09:44.105590Z"
    }
   },
   "cell_type": "code",
   "source": [
    "\n",
    "from tqdm import tqdm\n",
    "from multiprocessing import Pool, RLock, freeze_support\n",
    "\n",
    "L = list(range(9))\n",
    "\n",
    "\n",
    "def progresser(n):\n",
    "    interval = 0.001 / (n + 2)\n",
    "    total = 5000\n",
    "    text = f\"#{n}, est. {interval * total:<04.2}s\"\n",
    "    for _ in trange(total, desc=text, position=n):\n",
    "        sleep(interval)\n",
    "\n",
    "\n",
    "freeze_support()  # for Windows support\n",
    "tqdm.set_lock(RLock())  # for managing output contention\n",
    "\n",
    "p = Pool(initializer=tqdm.set_lock, initargs=(tqdm.get_lock(),))\n",
    "p.map(progresser, L)"
   ],
   "id": "287762e35456835b",
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Process SpawnPoolWorker-1:\n",
      "Traceback (most recent call last):\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 313, in _bootstrap\n",
      "    self.run()\n",
      "    ~~~~~~~~^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 108, in run\n",
      "    self._target(*self._args, **self._kwargs)\n",
      "    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/pool.py\", line 114, in worker\n",
      "    task = get()\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/queues.py\", line 387, in get\n",
      "    return _ForkingPickler.loads(res)\n",
      "           ~~~~~~~~~~~~~~~~~~~~~^^^^^\n",
      "AttributeError: Can't get attribute 'progresser' on <module '__main__' (<class '_frozen_importlib.BuiltinImporter'>)>\n",
      "Process SpawnPoolWorker-2:\n",
      "Process SpawnPoolWorker-4:\n",
      "Traceback (most recent call last):\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 313, in _bootstrap\n",
      "    self.run()\n",
      "    ~~~~~~~~^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 108, in run\n",
      "    self._target(*self._args, **self._kwargs)\n",
      "    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/pool.py\", line 114, in worker\n",
      "    task = get()\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/queues.py\", line 387, in get\n",
      "    return _ForkingPickler.loads(res)\n",
      "           ~~~~~~~~~~~~~~~~~~~~~^^^^^\n",
      "AttributeError: Can't get attribute 'progresser' on <module '__main__' (<class '_frozen_importlib.BuiltinImporter'>)>\n",
      "Process SpawnPoolWorker-3:\n",
      "Traceback (most recent call last):\n",
      "Process SpawnPoolWorker-6:\n",
      "Traceback (most recent call last):\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 313, in _bootstrap\n",
      "    self.run()\n",
      "    ~~~~~~~~^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 108, in run\n",
      "    self._target(*self._args, **self._kwargs)\n",
      "    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/pool.py\", line 114, in worker\n",
      "    task = get()\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/queues.py\", line 387, in get\n",
      "    return _ForkingPickler.loads(res)\n",
      "           ~~~~~~~~~~~~~~~~~~~~~^^^^^\n",
      "AttributeError: Can't get attribute 'progresser' on <module '__main__' (<class '_frozen_importlib.BuiltinImporter'>)>\n",
      "Traceback (most recent call last):\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 313, in _bootstrap\n",
      "    self.run()\n",
      "    ~~~~~~~~^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 313, in _bootstrap\n",
      "    self.run()\n",
      "    ~~~~~~~~^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 108, in run\n",
      "    self._target(*self._args, **self._kwargs)\n",
      "    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/pool.py\", line 114, in worker\n",
      "    task = get()\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/queues.py\", line 387, in get\n",
      "    return _ForkingPickler.loads(res)\n",
      "           ~~~~~~~~~~~~~~~~~~~~~^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 108, in run\n",
      "    self._target(*self._args, **self._kwargs)\n",
      "    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/pool.py\", line 114, in worker\n",
      "    task = get()\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/queues.py\", line 387, in get\n",
      "    return _ForkingPickler.loads(res)\n",
      "           ~~~~~~~~~~~~~~~~~~~~~^^^^^\n",
      "AttributeError: Can't get attribute 'progresser' on <module '__main__' (<class '_frozen_importlib.BuiltinImporter'>)>\n",
      "AttributeError: Can't get attribute 'progresser' on <module '__main__' (<class '_frozen_importlib.BuiltinImporter'>)>\n",
      "Process SpawnPoolWorker-5:\n",
      "Traceback (most recent call last):\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 313, in _bootstrap\n",
      "    self.run()\n",
      "    ~~~~~~~~^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 108, in run\n",
      "    self._target(*self._args, **self._kwargs)\n",
      "    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/pool.py\", line 114, in worker\n",
      "    task = get()\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/queues.py\", line 387, in get\n",
      "    return _ForkingPickler.loads(res)\n",
      "           ~~~~~~~~~~~~~~~~~~~~~^^^^^\n",
      "AttributeError: Can't get attribute 'progresser' on <module '__main__' (<class '_frozen_importlib.BuiltinImporter'>)>\n",
      "Process SpawnPoolWorker-8:\n",
      "Traceback (most recent call last):\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 313, in _bootstrap\n",
      "    self.run()\n",
      "    ~~~~~~~~^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 108, in run\n",
      "    self._target(*self._args, **self._kwargs)\n",
      "    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/pool.py\", line 114, in worker\n",
      "    task = get()\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/queues.py\", line 387, in get\n",
      "    return _ForkingPickler.loads(res)\n",
      "           ~~~~~~~~~~~~~~~~~~~~~^^^^^\n",
      "AttributeError: Can't get attribute 'progresser' on <module '__main__' (<class '_frozen_importlib.BuiltinImporter'>)>\n",
      "Process SpawnPoolWorker-7:\n",
      "Traceback (most recent call last):\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 313, in _bootstrap\n",
      "    self.run()\n",
      "    ~~~~~~~~^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 108, in run\n",
      "    self._target(*self._args, **self._kwargs)\n",
      "    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/pool.py\", line 114, in worker\n",
      "    task = get()\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/queues.py\", line 387, in get\n",
      "    return _ForkingPickler.loads(res)\n",
      "           ~~~~~~~~~~~~~~~~~~~~~^^^^^\n",
      "AttributeError: Can't get attribute 'progresser' on <module '__main__' (<class '_frozen_importlib.BuiltinImporter'>)>\n",
      "Process SpawnPoolWorker-12:\n",
      "Traceback (most recent call last):\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 313, in _bootstrap\n",
      "    self.run()\n",
      "    ~~~~~~~~^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 108, in run\n",
      "    self._target(*self._args, **self._kwargs)\n",
      "    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/pool.py\", line 114, in worker\n",
      "    task = get()\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/queues.py\", line 387, in get\n",
      "    return _ForkingPickler.loads(res)\n",
      "           ~~~~~~~~~~~~~~~~~~~~~^^^^^\n",
      "AttributeError: Can't get attribute 'progresser' on <module '__main__' (<class '_frozen_importlib.BuiltinImporter'>)>\n",
      "Process SpawnPoolWorker-20:\n",
      "Process SpawnPoolWorker-19:\n",
      "Process SpawnPoolWorker-21:\n",
      "Process SpawnPoolWorker-17:\n",
      "Process SpawnPoolWorker-15:\n",
      "Process SpawnPoolWorker-18:\n",
      "Process SpawnPoolWorker-14:\n",
      "Process SpawnPoolWorker-9:\n",
      "Process SpawnPoolWorker-11:\n",
      "Process SpawnPoolWorker-13:\n",
      "Process SpawnPoolWorker-10:\n",
      "Process SpawnPoolWorker-16:\n",
      "Traceback (most recent call last):\n",
      "Traceback (most recent call last):\n",
      "Traceback (most recent call last):\n",
      "Traceback (most recent call last):\n",
      "Traceback (most recent call last):\n",
      "Traceback (most recent call last):\n",
      "Traceback (most recent call last):\n",
      "Traceback (most recent call last):\n",
      "Traceback (most recent call last):\n",
      "Traceback (most recent call last):\n",
      "Traceback (most recent call last):\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 313, in _bootstrap\n",
      "    self.run()\n",
      "    ~~~~~~~~^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 313, in _bootstrap\n",
      "    self.run()\n",
      "    ~~~~~~~~^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 108, in run\n",
      "    self._target(*self._args, **self._kwargs)\n",
      "    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/pool.py\", line 114, in worker\n",
      "    task = get()\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 108, in run\n",
      "    self._target(*self._args, **self._kwargs)\n",
      "    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/queues.py\", line 384, in get\n",
      "    with self._rlock:\n",
      "         ^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/pool.py\", line 114, in worker\n",
      "    task = get()\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/synchronize.py\", line 95, in __enter__\n",
      "    return self._semlock.__enter__()\n",
      "           ~~~~~~~~~~~~~~~~~~~~~~~^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/queues.py\", line 384, in get\n",
      "    with self._rlock:\n",
      "         ^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/synchronize.py\", line 95, in __enter__\n",
      "    return self._semlock.__enter__()\n",
      "           ~~~~~~~~~~~~~~~~~~~~~~~^^\n",
      "KeyboardInterrupt\n",
      "KeyboardInterrupt\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 313, in _bootstrap\n",
      "    self.run()\n",
      "    ~~~~~~~~^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 313, in _bootstrap\n",
      "    self.run()\n",
      "    ~~~~~~~~^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 108, in run\n",
      "    self._target(*self._args, **self._kwargs)\n",
      "    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 108, in run\n",
      "    self._target(*self._args, **self._kwargs)\n",
      "    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/pool.py\", line 114, in worker\n",
      "    task = get()\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/pool.py\", line 114, in worker\n",
      "    task = get()\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/queues.py\", line 384, in get\n",
      "    with self._rlock:\n",
      "         ^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/queues.py\", line 384, in get\n",
      "    with self._rlock:\n",
      "         ^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/synchronize.py\", line 95, in __enter__\n",
      "    return self._semlock.__enter__()\n",
      "           ~~~~~~~~~~~~~~~~~~~~~~~^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/synchronize.py\", line 95, in __enter__\n",
      "    return self._semlock.__enter__()\n",
      "           ~~~~~~~~~~~~~~~~~~~~~~~^^\n",
      "KeyboardInterrupt\n",
      "KeyboardInterrupt\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 313, in _bootstrap\n",
      "    self.run()\n",
      "    ~~~~~~~~^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 108, in run\n",
      "    self._target(*self._args, **self._kwargs)\n",
      "    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/pool.py\", line 114, in worker\n",
      "    task = get()\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/queues.py\", line 384, in get\n",
      "    with self._rlock:\n",
      "         ^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 313, in _bootstrap\n",
      "    self.run()\n",
      "    ~~~~~~~~^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/synchronize.py\", line 95, in __enter__\n",
      "    return self._semlock.__enter__()\n",
      "           ~~~~~~~~~~~~~~~~~~~~~~~^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 108, in run\n",
      "    self._target(*self._args, **self._kwargs)\n",
      "    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/pool.py\", line 114, in worker\n",
      "    task = get()\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/queues.py\", line 384, in get\n",
      "    with self._rlock:\n",
      "         ^^^^^^^^^^^\n",
      "KeyboardInterrupt\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/synchronize.py\", line 95, in __enter__\n",
      "    return self._semlock.__enter__()\n",
      "           ~~~~~~~~~~~~~~~~~~~~~~~^^\n",
      "KeyboardInterrupt\n",
      "Traceback (most recent call last):\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 313, in _bootstrap\n",
      "    self.run()\n",
      "    ~~~~~~~~^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 108, in run\n",
      "    self._target(*self._args, **self._kwargs)\n",
      "    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/pool.py\", line 114, in worker\n",
      "    task = get()\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/queues.py\", line 384, in get\n",
      "    with self._rlock:\n",
      "         ^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/synchronize.py\", line 95, in __enter__\n",
      "    return self._semlock.__enter__()\n",
      "           ~~~~~~~~~~~~~~~~~~~~~~~^^\n",
      "KeyboardInterrupt\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 313, in _bootstrap\n",
      "    self.run()\n",
      "    ~~~~~~~~^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 108, in run\n",
      "    self._target(*self._args, **self._kwargs)\n",
      "    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/pool.py\", line 114, in worker\n",
      "    task = get()\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/queues.py\", line 385, in get\n",
      "    res = self._reader.recv_bytes()\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/connection.py\", line 216, in recv_bytes\n",
      "    buf = self._recv_bytes(maxlength)\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/connection.py\", line 430, in _recv_bytes\n",
      "    buf = self._recv(4)\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/connection.py\", line 395, in _recv\n",
      "    chunk = read(handle, remaining)\n",
      "KeyboardInterrupt\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 313, in _bootstrap\n",
      "    self.run()\n",
      "    ~~~~~~~~^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 108, in run\n",
      "    self._target(*self._args, **self._kwargs)\n",
      "    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/pool.py\", line 114, in worker\n",
      "    task = get()\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/queues.py\", line 384, in get\n",
      "    with self._rlock:\n",
      "         ^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/synchronize.py\", line 95, in __enter__\n",
      "    return self._semlock.__enter__()\n",
      "           ~~~~~~~~~~~~~~~~~~~~~~~^^\n",
      "KeyboardInterrupt\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 313, in _bootstrap\n",
      "    self.run()\n",
      "    ~~~~~~~~^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 108, in run\n",
      "    self._target(*self._args, **self._kwargs)\n",
      "    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/pool.py\", line 114, in worker\n",
      "    task = get()\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/queues.py\", line 384, in get\n",
      "    with self._rlock:\n",
      "         ^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/synchronize.py\", line 95, in __enter__\n",
      "    return self._semlock.__enter__()\n",
      "           ~~~~~~~~~~~~~~~~~~~~~~~^^\n",
      "KeyboardInterrupt\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 313, in _bootstrap\n",
      "    self.run()\n",
      "    ~~~~~~~~^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 108, in run\n",
      "    self._target(*self._args, **self._kwargs)\n",
      "    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/pool.py\", line 114, in worker\n",
      "    task = get()\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/queues.py\", line 384, in get\n",
      "    with self._rlock:\n",
      "         ^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/synchronize.py\", line 95, in __enter__\n",
      "    return self._semlock.__enter__()\n",
      "           ~~~~~~~~~~~~~~~~~~~~~~~^^\n",
      "KeyboardInterrupt\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 313, in _bootstrap\n",
      "    self.run()\n",
      "    ~~~~~~~~^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/process.py\", line 108, in run\n",
      "    self._target(*self._args, **self._kwargs)\n",
      "    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/pool.py\", line 114, in worker\n",
      "    task = get()\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/queues.py\", line 384, in get\n",
      "    with self._rlock:\n",
      "         ^^^^^^^^^^^\n",
      "  File \"/Users/liuzhenzhou/anaconda3/envs/python313/lib/python3.13/multiprocessing/synchronize.py\", line 95, in __enter__\n",
      "    return self._semlock.__enter__()\n",
      "           ~~~~~~~~~~~~~~~~~~~~~~~^^\n",
      "KeyboardInterrupt\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001B[31m---------------------------------------------------------------------------\u001B[39m",
      "\u001B[31mKeyboardInterrupt\u001B[39m                         Traceback (most recent call last)",
      "\u001B[36mCell\u001B[39m\u001B[36m \u001B[39m\u001B[32mIn[9]\u001B[39m\u001B[32m, line 19\u001B[39m\n\u001B[32m     16\u001B[39m tqdm.set_lock(RLock())  \u001B[38;5;66;03m# for managing output contention\u001B[39;00m\n\u001B[32m     18\u001B[39m p = Pool(initializer=tqdm.set_lock, initargs=(tqdm.get_lock(),))\n\u001B[32m---> \u001B[39m\u001B[32m19\u001B[39m \u001B[43mp\u001B[49m\u001B[43m.\u001B[49m\u001B[43mmap\u001B[49m\u001B[43m(\u001B[49m\u001B[43mprogresser\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mL\u001B[49m\u001B[43m)\u001B[49m\n",
      "\u001B[36mFile \u001B[39m\u001B[32m~/anaconda3/envs/python313/lib/python3.13/multiprocessing/pool.py:367\u001B[39m, in \u001B[36mPool.map\u001B[39m\u001B[34m(self, func, iterable, chunksize)\u001B[39m\n\u001B[32m    362\u001B[39m \u001B[38;5;28;01mdef\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34mmap\u001B[39m(\u001B[38;5;28mself\u001B[39m, func, iterable, chunksize=\u001B[38;5;28;01mNone\u001B[39;00m):\n\u001B[32m    363\u001B[39m \u001B[38;5;250m    \u001B[39m\u001B[33;03m'''\u001B[39;00m\n\u001B[32m    364\u001B[39m \u001B[33;03m    Apply `func` to each element in `iterable`, collecting the results\u001B[39;00m\n\u001B[32m    365\u001B[39m \u001B[33;03m    in a list that is returned.\u001B[39;00m\n\u001B[32m    366\u001B[39m \u001B[33;03m    '''\u001B[39;00m\n\u001B[32m--> \u001B[39m\u001B[32m367\u001B[39m     \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43m_map_async\u001B[49m\u001B[43m(\u001B[49m\u001B[43mfunc\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43miterable\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mmapstar\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mchunksize\u001B[49m\u001B[43m)\u001B[49m\u001B[43m.\u001B[49m\u001B[43mget\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m\n",
      "\u001B[36mFile \u001B[39m\u001B[32m~/anaconda3/envs/python313/lib/python3.13/multiprocessing/pool.py:768\u001B[39m, in \u001B[36mApplyResult.get\u001B[39m\u001B[34m(self, timeout)\u001B[39m\n\u001B[32m    767\u001B[39m \u001B[38;5;28;01mdef\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34mget\u001B[39m(\u001B[38;5;28mself\u001B[39m, timeout=\u001B[38;5;28;01mNone\u001B[39;00m):\n\u001B[32m--> \u001B[39m\u001B[32m768\u001B[39m     \u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43mwait\u001B[49m\u001B[43m(\u001B[49m\u001B[43mtimeout\u001B[49m\u001B[43m)\u001B[49m\n\u001B[32m    769\u001B[39m     \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28mself\u001B[39m.ready():\n\u001B[32m    770\u001B[39m         \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mTimeoutError\u001B[39;00m\n",
      "\u001B[36mFile \u001B[39m\u001B[32m~/anaconda3/envs/python313/lib/python3.13/multiprocessing/pool.py:765\u001B[39m, in \u001B[36mApplyResult.wait\u001B[39m\u001B[34m(self, timeout)\u001B[39m\n\u001B[32m    764\u001B[39m \u001B[38;5;28;01mdef\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34mwait\u001B[39m(\u001B[38;5;28mself\u001B[39m, timeout=\u001B[38;5;28;01mNone\u001B[39;00m):\n\u001B[32m--> \u001B[39m\u001B[32m765\u001B[39m     \u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43m_event\u001B[49m\u001B[43m.\u001B[49m\u001B[43mwait\u001B[49m\u001B[43m(\u001B[49m\u001B[43mtimeout\u001B[49m\u001B[43m)\u001B[49m\n",
      "\u001B[36mFile \u001B[39m\u001B[32m~/anaconda3/envs/python313/lib/python3.13/threading.py:659\u001B[39m, in \u001B[36mEvent.wait\u001B[39m\u001B[34m(self, timeout)\u001B[39m\n\u001B[32m    657\u001B[39m signaled = \u001B[38;5;28mself\u001B[39m._flag\n\u001B[32m    658\u001B[39m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m signaled:\n\u001B[32m--> \u001B[39m\u001B[32m659\u001B[39m     signaled = \u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43m_cond\u001B[49m\u001B[43m.\u001B[49m\u001B[43mwait\u001B[49m\u001B[43m(\u001B[49m\u001B[43mtimeout\u001B[49m\u001B[43m)\u001B[49m\n\u001B[32m    660\u001B[39m \u001B[38;5;28;01mreturn\u001B[39;00m signaled\n",
      "\u001B[36mFile \u001B[39m\u001B[32m~/anaconda3/envs/python313/lib/python3.13/threading.py:359\u001B[39m, in \u001B[36mCondition.wait\u001B[39m\u001B[34m(self, timeout)\u001B[39m\n\u001B[32m    357\u001B[39m \u001B[38;5;28;01mtry\u001B[39;00m:    \u001B[38;5;66;03m# restore state no matter what (e.g., KeyboardInterrupt)\u001B[39;00m\n\u001B[32m    358\u001B[39m     \u001B[38;5;28;01mif\u001B[39;00m timeout \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m:\n\u001B[32m--> \u001B[39m\u001B[32m359\u001B[39m         \u001B[43mwaiter\u001B[49m\u001B[43m.\u001B[49m\u001B[43macquire\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m\n\u001B[32m    360\u001B[39m         gotit = \u001B[38;5;28;01mTrue\u001B[39;00m\n\u001B[32m    361\u001B[39m     \u001B[38;5;28;01melse\u001B[39;00m:\n",
      "\u001B[31mKeyboardInterrupt\u001B[39m: "
     ]
    }
   ],
   "execution_count": 9
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-18T14:10:15.901046Z",
     "start_time": "2025-03-18T14:10:15.690903Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# Due to popular demand we’ve added support for pandas – here’s an example for DataFrame.progress_apply and DataFrameGroupBy.progress_apply:\n",
    "\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "from tqdm import tqdm\n",
    "\n",
    "df = pd.DataFrame(np.random.randint(0, 100, (100000, 6)))\n",
    "\n",
    "# Register `pandas.progress_apply` and `pandas.Series.map_apply` with `tqdm`\n",
    "# (can use `tqdm.gui.tqdm`, `tqdm.notebook.tqdm`, optional kwargs, etc.)\n",
    "tqdm.pandas(desc=\"my bar!\")\n",
    "\n",
    "# Now you can use `progress_apply` instead of `apply`\n",
    "# and `progress_map` instead of `map`\n",
    "df.progress_apply(lambda x: x ** 2)\n",
    "# can also groupby:\n",
    "# df.groupby(0).progress_apply(lambda x: x**2)"
   ],
   "id": "44c0491235101fa1",
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "my bar!: 100%|██████████| 6/6 [00:00<00:00, 1522.43it/s]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "          0     1     2     3     4     5\n",
       "0      7569  2601  4096  1600    36     1\n",
       "1      3136   729   289  2809   529    81\n",
       "2      1681  1444  2500  5041  8836  6561\n",
       "3      1156  1681  1089  7744  2916     9\n",
       "4       784  5476  4225  9801  1849  5041\n",
       "...     ...   ...   ...   ...   ...   ...\n",
       "99995    81  1600  3136  1681    16     4\n",
       "99996   289  9801  5625  1764  6400  2916\n",
       "99997   784  6084  2916  1849  5329  1681\n",
       "99998  2500  8464  8464  2704  7225  9025\n",
       "99999  2401  8100  6241  4624   256   144\n",
       "\n",
       "[100000 rows x 6 columns]"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>7569</td>\n",
       "      <td>2601</td>\n",
       "      <td>4096</td>\n",
       "      <td>1600</td>\n",
       "      <td>36</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3136</td>\n",
       "      <td>729</td>\n",
       "      <td>289</td>\n",
       "      <td>2809</td>\n",
       "      <td>529</td>\n",
       "      <td>81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1681</td>\n",
       "      <td>1444</td>\n",
       "      <td>2500</td>\n",
       "      <td>5041</td>\n",
       "      <td>8836</td>\n",
       "      <td>6561</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1156</td>\n",
       "      <td>1681</td>\n",
       "      <td>1089</td>\n",
       "      <td>7744</td>\n",
       "      <td>2916</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>784</td>\n",
       "      <td>5476</td>\n",
       "      <td>4225</td>\n",
       "      <td>9801</td>\n",
       "      <td>1849</td>\n",
       "      <td>5041</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99995</th>\n",
       "      <td>81</td>\n",
       "      <td>1600</td>\n",
       "      <td>3136</td>\n",
       "      <td>1681</td>\n",
       "      <td>16</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99996</th>\n",
       "      <td>289</td>\n",
       "      <td>9801</td>\n",
       "      <td>5625</td>\n",
       "      <td>1764</td>\n",
       "      <td>6400</td>\n",
       "      <td>2916</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99997</th>\n",
       "      <td>784</td>\n",
       "      <td>6084</td>\n",
       "      <td>2916</td>\n",
       "      <td>1849</td>\n",
       "      <td>5329</td>\n",
       "      <td>1681</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99998</th>\n",
       "      <td>2500</td>\n",
       "      <td>8464</td>\n",
       "      <td>8464</td>\n",
       "      <td>2704</td>\n",
       "      <td>7225</td>\n",
       "      <td>9025</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99999</th>\n",
       "      <td>2401</td>\n",
       "      <td>8100</td>\n",
       "      <td>6241</td>\n",
       "      <td>4624</td>\n",
       "      <td>256</td>\n",
       "      <td>144</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>100000 rows × 6 columns</p>\n",
       "</div>"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 10
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-18T14:10:26.424792Z",
     "start_time": "2025-03-18T14:10:22.756590Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from tqdm.notebook import trange, tqdm\n",
    "from time import sleep\n",
    "\n",
    "for i in trange(3, desc='1st loop'):\n",
    "    for j in tqdm(range(100), desc='2nd loop'):\n",
    "        sleep(0.01)"
   ],
   "id": "edd1991463e7363e",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1st loop:   0%|          | 0/3 [00:00<?, ?it/s]"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "44616c5389694d06978ab3a2cdeaed18"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "2nd loop:   0%|          | 0/100 [00:00<?, ?it/s]"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "4237608df45548d59b9aa1e7156e1d97"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "2nd loop:   0%|          | 0/100 [00:00<?, ?it/s]"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "032b318dcd7c436e943bcbf61daea83c"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "2nd loop:   0%|          | 0/100 [00:00<?, ?it/s]"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "005b8d2aaab2427d9d81aa437123d4f8"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "execution_count": 11
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
